package edu.friday.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import edu.friday.model.vo.SysUserVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class LoginUser implements UserDetails {
    private static final long serialVersionUID = 1L;
    private String token;

    private Long loginTime;
    private Long expireTime;

    private String ipAddress;
    private String loginLocation;

    private String browser;

    private String os;

    private Set<String> permissions;

    private SysUserVO user;

    public LoginUser(SysUserVO user,Set<String> permissions){
        this.user = user;
        this.permissions = permissions;
    }
    @JsonIgnore
    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUserName();
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired () {
        return true;
    }
    @JsonIgnore
    @Override
    public boolean isAccountNonLocked () {
        return true;
    }
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired () {
        return true;
    }
    @JsonIgnore
    @Override
    public boolean isEnabled () {
        return true;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }
}
